package com.lmiot.xyclick.Util;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Vibrator;
import com.lmiot.xyclick.App.MyApp;
import com.lkx.liandianqinew.R;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionAsSDK;

public class ClickUtils {
    private static MediaPlayer mediaPlayer;
    private static MediaPlayer mediaPlayerShake;
    private static MediaPlayer mediaPlayerVoice;
    private static Vibrator vibrator;
    private static Vibrator vibratorLong;

    public static void showClick(Context context) {
        if (!ActionAsSDK.getCloseAllVibrate(MyApp.getContext())) {
            try {
                if (vibrator == null) {
                    vibrator = (Vibrator) context.getSystemService("vibrator");
                }
                vibrator.vibrate(80);
                if (mediaPlayer == null) {
                    mediaPlayer = MediaPlayer.create(context, (int) R.raw.pointsound);
                }
                mediaPlayer.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static void Click(Context context) {
        try {
            if (!ActionAsSDK.getCloseAllVibrate(MyApp.getContext())) {
                if (vibrator == null) {
                    vibrator = (Vibrator) context.getSystemService("vibrator");
                }
                vibrator.vibrate(50);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onlyVice(Context context) {
        try {
            if (!ActionAsSDK.getCloseAllVibrate(MyApp.getContext())) {
                if (mediaPlayerVoice == null) {
                    mediaPlayerVoice = MediaPlayer.create(context, (int) R.raw.pointsound);
                }
                mediaPlayerVoice.start();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onlyVibrate(Context context) {
        try {
            if (!ActionAsSDK.getCloseAllVibrate(MyApp.getContext())) {
                if (vibrator == null) {
                    vibrator = (Vibrator) context.getSystemService("vibrator");
                }
                vibrator.vibrate(80);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onlyVibrate(Context context, int i) {
        try {
            if (!ActionAsSDK.getCloseAllVibrate(MyApp.getContext())) {
                if (vibratorLong == null) {
                    vibratorLong = (Vibrator) context.getSystemService("vibrator");
                }
                vibratorLong.vibrate((long) i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
